package org.example.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class FanoutListener {
    //    @RabbitListener(queues = "hello.queue1")
//    public void listenerSimpleQueueMessage(String msg)throws MessageConversionException{
//        System.out.println("打印消息:"+msg);
//        if(false){
//            throw new MessageConversionException("故意的");
//        }
//    }
//    @RabbitListener(queues="hello.queue2")
//    public void Query1(String msg) throws InterruptedException {
//        System.out.println("刘某处理消息:"+msg);
//        Thread.sleep(20);
//    }
//    @RabbitListener(queues="hello.queue2")
//    public void Query2(String msg) throws InterruptedException {
//        System.out.println("李某处理消息:"+msg);
//        Thread.sleep(200);
//    }
    @RabbitListener(queues = "fanout.queue1")
    public void Query1(String msg) throws InterruptedException {
        System.out.println("刘某处理消息:" + msg);
        Thread.sleep(20);
    }
    @RabbitListener(queues = "fanout.queue2")
    public void Query2(String msg) throws InterruptedException {
        System.out.println("李某处理消息:" + msg);
        Thread.sleep(200);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue1",durable = "true"),
            exchange = @Exchange(name = "test.direct",type = ExchangeTypes.DIRECT),
            key = {"red","blue"}
    ))
    public void Query3(String msg) throws InterruptedException {
        System.out.println("李某处理消息:" + msg);
        Thread.sleep(200);
    }
}
